<div class="layui-card layadmin-header">
  <div class="layui-breadcrumb" lay-filter="breadcrumb">
    <a><cite>活动管理</cite></a>
    <a><cite>编辑邀请活动</cite></a>
  </div>
</div>

<script type="text/html" template lay-done="layui.data.done(d.params)">
  <div class="layui-form" lay-filter="form_online">
    {{# var data = d.params || {} }}
    <div class="layui-form-item">
      <label class="layui-form-label">活动名称</label>
      <div class="layui-input-inline" style="width: 300px">
        <input name="name" type="text" lay-verify="required" class="layui-input" value="{{data.name || ''}}"/>
      </div>
    </div>
    <div class="layui-form-item">
      <div class="layui-inline">
        <label class="layui-form-label form-required">开始日期</label>
        <div class="layui-input-inline">
          <input type="text" id="start_date" class="layui-input" name="start_date" placeholder="请选择开始日期"
                 autocomplete="off" value="{{data.start_date || ''}}" lay-verify="required">
        </div>
      </div>
      <div class="layui-inline">
        <label class="layui-form-label form-required">结束日期</label>
        <div class="layui-input-inline">
          <input type="text" id="end_date" class="layui-input" name="end_date" placeholder="请选择结束日期"
                 autocomplete="off" value="{{data.end_date || ''}}" lay-verify="required">
        </div>
      </div>
    </div>
    <div class="layui-form-item">
      <div class="layui-inline">
        <label class="layui-form-label">榜单位数</label>
        <div class="layui-input-inline">
          <input type="number" class="layui-input" lay-verify="required" name="ranking_num"
                 value="{{data.ranking_num || ''}}">
        </div>
      </div>
      <div class="layui-inline">
        <div class="layui-form-item">
          <label class="layui-form-label">消费限制</label>
          <div class="layui-input-inline">
            <input type="checkbox" name="enable_consume" lay-skin="switch" lay-text="是|否"
                   {{data.enable_consume==1?'checked':''}} {{# if(data.id) { }} disabled {{# } }} >
          </div>
        </div>
      </div>
    </div>
    <div class="layui-form-item">
      <label class="layui-form-label form-required" id="logo_label">海报封面</label>
      <div class="layui-input-inline">
        <div id="image_url"></div>
      </div>
    </div>
    {{# if (data.id) { }}
    <div class="layui-form-item" style="display: none">
      <div class="layui-inline">
        <label class="layui-form-label">id</label>
        <div class="layui-input-inline">
          <input type="text" class="layui-input" lay-verify="required" name="id"
                 value="{{data.id || ''}}">
        </div>
      </div>
    </div>
    {{# } }}
    <div class="layui-card-body layui-row layui-col-space10">
      <div class="layui-col-md6">
        <div class="layui-form-item">
          <label class="layui-form-label"></label>
          <div class="layui-input-inline">
            <a class="layui-btn" lay-submit lay-filter="submit_invite">保存</a>
          </div>
        </div>
      </div>
    </div>
  </div>
</script>
<script>
  layui.data.done = function (obj) {
    layui.use(['step', 'fox_upload', 'laydate'], function () {
      let $ = layui.$
        , form = layui.form
        , admin = layui.admin
        , fox_upload = layui.fox_upload
        , laydate = layui.laydate

      form.render()
      if (obj.id && obj.ongoing_status.value != 'not_start') {
        $('#start_date').attr('disabled', true)
      }

      //日历初始化
      laydate.render({
        elem: '#start_date'
        , type: 'date'
      });
      laydate.render({
        elem: '#end_date'
        , type: 'date'
      });

      //上传控件初始化
      fox_upload.render({
        elem: '#image_url'
        , url: 'agent-admin/products/image'
        , headers: {
          Authorization: admin.getAccessToken('Bearer')
        }
        , text: '点击上传'
        , name: 'img_url'
        , value: obj.img_url || ''
      })
    })
  }
</script>

